home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Full / NetObjects Fusion 9 Standard / NOF9_Full_EN.exe / data1.cab / FSI / lib / innovative / IS.js < prev    next >
Encoding:
JavaScript  |  2005-11-16  |  9.3 KB  |  420 lines

  1. /****i* SOURCE_FILE/INFO
  2.  *
  3.  * NAME
  4.  *    IS.js
  5.  *
  6.  * USAGE
  7.  *    Part of IS JavaScript Library.
  8.  *
  9.  * COPYRIGHT
  10.  *    Copyright ⌐ 1999-2000 Innovative Systems SRL.
  11.  *    All Rights Reserved.
  12.  *
  13.  *  This is an unpublished work protected by Innovative Systems SRL
  14.  *  as a trade secret, and is not to be used or disclosed except as
  15.  *  expressly provided in a written license agreement executed by
  16.  *  you and Innovative Systems SRL.
  17.  *
  18.  *      <copyright@innovative.ro>
  19.  *
  20.  * NOTES
  21.  *    JavaScript code.
  22.  *
  23.  *****/
  24.  
  25. /****h* IS_JavaScript_Library/IS
  26.  *
  27.  * NAME
  28.  *    IS JavaScript Library / main module.
  29.  *
  30.  * DESCRIPTION
  31.  *    Definition of IS "namespace".
  32.  *
  33.  * NOTES
  34.  *    (*) To place another name under this namespace use:
  35.  *        IS.prototype.<your-name> = <whatever>;
  36.  *
  37.  *    (*) This file also contains an instance of the ISLib object.
  38.  *
  39.  ****/
  40.  
  41. function IS_getLibHandle()
  42. {
  43.   return ((typeof(top) != "undefined" && typeof(top._is) != "undefined") ? top._is :  // browsers
  44.          ((typeof(top) != "undefined" && typeof(top.opener) != "undefined" && top.opener != null && typeof(top.opener._is) != "undefined") ? top.opener._is :  // browsers  
  45.          ((typeof(MM)  != "undefined" && typeof(MM._is) != "undefined") ? MM._is :    // MacroMedia DW
  46.          ((typeof(_is) != "undefined") ? _is : null))));                              // ??
  47. }
  48.  
  49. var IS = IS_getLibHandle();
  50. if ( IS == null )
  51. {
  52. /****m* ISJS/instanceOf
  53.  *
  54.  * NAME
  55.  *    instanceOf( object, constructor )
  56.  *
  57.  * USAGE
  58.  *    object      -- object instance
  59.  *    constructor -- class constructor
  60.  *
  61.  * DESCRIPTION
  62.  *    Tests if an object instance is of a specified class.
  63.  *
  64.  * RETURN VALUE
  65.  *    true -- if 'object' is an instance of type 'constructor'
  66.  *    false -- in any other case
  67.  *
  68.  ****/
  69. function IS_instanceOf (object, constructor)
  70. {
  71.   while (object != null)
  72.   {
  73.     if (object == constructor.prototype)
  74.     {
  75.       return true;
  76.     }
  77.     object = object.__proto__;
  78.   }
  79.  
  80.   return false;
  81. }
  82.  
  83.  
  84. /****m* ISJS/addVariable
  85.  *
  86.  * NAME
  87.  *    addVariable( name, initValue )
  88.  *
  89.  * USAGE
  90.  *    name      -- variable name
  91.  *    initValue -- initial value
  92.  *
  93.  * DESCRIPTION
  94.  *    Adds a new variable, 'name', to ISJSLib namespace. If 'initValue' is specified
  95.  *    the new variable will be initialized with this value.
  96.  *
  97.  * RETURN VALUE
  98.  *    none
  99.  *
  100.  ****/
  101. function IS_addVariable( name, initValue )
  102. {
  103.   if ( arguments.length == 0 ) { return; }
  104.   if ( arguments.length == 1 ) { initValue = null; }
  105.  
  106.   eval( "IS." + name + " = initValue" );
  107. }
  108.  
  109.  
  110. /****m* ISJS/delVariable
  111.  *
  112.  * NAME
  113.  *    delVariable( name )
  114.  *
  115.  * USAGE
  116.  *    name -- variable name
  117.  *
  118.  * DESCRIPTION
  119.  *    Removes a variable, 'name', from ISJSLib namespace
  120.  *
  121.  * RETURN VALUE
  122.  *    none
  123.  *
  124.  ****/
  125. function IS_delVariable( name )
  126. {
  127.   if ( arguments.length == 0 ) { return; }
  128.       
  129.   if ( typeof( eval( "IS." + name ) ) != "undefined" ) {
  130.     eval( "delete IS." + name );
  131.   }
  132. }
  133.  
  134.  
  135. /****m* IS/setLibPath
  136.  *
  137.  * NAME
  138.  *    setLibPath( path )
  139.  *
  140.  * USAGE
  141.  *    path: the ISJS library path
  142.  *
  143.  * DESCRIPTION
  144.  *    Sets the path of the ISJS library. The path will be used as a default for
  145.  *  all module loading operations.
  146.  *
  147.  * RETURN VALUE
  148.  *    none
  149.  *
  150.  * SEE ALSO
  151.  *   IS/getLibPath
  152.  *   IS/loadModule
  153.  ****/
  154.  
  155. function IS_setLibPath (path)
  156. {
  157.   IS_addVariable ("LIB_PATH", path);
  158. }
  159.  
  160. /****m* IS/getLibPath
  161.  *
  162.  * NAME
  163.  *    getLibPath()
  164.  *
  165.  * RETURN VALUE
  166.  *    libPath: the ISJS library path
  167.  *
  168.  * DESCRIPTION
  169.  *    Gets the path of the ISJS library
  170.  *
  171.  * SEE ALSO
  172.  *   IS/setLibPath
  173.  *   IS/loadModule
  174.  ****/
  175.  
  176. function IS_getLibPath (path)
  177. {
  178.   return (IS.LIB_PATH != null ? IS.LIB_PATH : ".");
  179. }
  180.  
  181. /****m* IS/loadModule
  182.  *
  183.  * NAME
  184.  *    loadModule( moduleList [, modulePath] )
  185.  *
  186.  * USAGE
  187.  *    includeList: list of include files
  188.  *
  189.  * RETURN VALUE
  190.  *    none
  191.  *
  192.  * DESCRIPTION
  193.  *    Includes all files specified in the 'includeList' into the current document.
  194.  *  Note that the files are included at the current document position, meaning
  195.  *  that the call can not be used to include a JS source file into another JS
  196.  *  source file, as the including file is already loaded.
  197.  *
  198.  * SEE ALSO
  199.  *   IS/getLibPath
  200.  *   IS/setLibPath
  201.  ****/
  202.  
  203. function IS_loadModule (module, loadPath)
  204. {
  205.   if (module != null)
  206.   {
  207.   if (loadPath == null) {
  208.     loadPath = IS_getLibPath ();
  209.   }
  210.   
  211.   if (typeof (module) != "string" && module.length != null)
  212.   {
  213.     for (var i = 0; i < module.length; i++)
  214.     {
  215.  
  216.       document.writeln (
  217.       //alert (
  218.          '<script language="JavaScript1.2" src="' + 
  219.                loadPath + '/' + module[i] + '">' + '</' + 'script>');
  220.     }
  221.   }
  222.   else
  223.   {
  224.       document.writeln (
  225.       //alert (
  226.          '<script language="JavaScript1.2" src="' + 
  227.                loadPath + '/' + module.toString () + '">' + '</' + 'script>');
  228.   }
  229.   }
  230. }
  231.  
  232. function IS_isModuleInitialized (moduleName)
  233. {  
  234.   var modulesList = moduleName.split(".");
  235.   var o;
  236.   var m = "";
  237.   for (var i=0;i<modulesList.length-1;i++) {
  238.     m += modulesList[i];
  239.     o = eval (m);
  240.     if (typeof(o) == "undefined")
  241.       return true;
  242.     m += ".";
  243.   }
  244.   o = eval(moduleName);
  245.   if (typeof(o) != "undefined")
  246.     return true;
  247.   return false;
  248. }
  249.   
  250. /****m* ISJS/getFrameByName
  251.  *
  252.  * NAME
  253.  *    getFrameByName( name, root )
  254.  *
  255.  * USAGE
  256.  *    name -- frame name
  257.  *    root -- where to start looking for the frame
  258.  *
  259.  * DESCRIPTION
  260.  *    Searches for a frame named 'name' in the 'root' object and in any of its frames.
  261.  *
  262.  * RETURN VALUE
  263.  *    [object] -- frame object, if a frame is found
  264.  *    null     -- in any other case
  265.  *
  266.  ****/
  267. function IS_getFrameByName( name, root )
  268. {
  269.     if ( arguments.length < 2 ) {
  270.     root = top;
  271.   }
  272.       
  273.     if ( name == root.name ) {
  274.     return root;
  275.   }
  276.     
  277.   // NOTE: the conditional code below was written due to a strange behavior of 
  278.   //    Microsoft's browsers. When a frame was loaded with an page stored outside of 
  279.   //    the local site the frame object properties could not be accessed any more (an
  280.   //    'Access is denied.' error will occur). Using this piece of code eliminates the 
  281.   //    problem.
  282.  
  283.   // <CONDITIONAL CODE>
  284.   // <Microsoft browsers>
  285.   if ( /Microsoft/.test( navigator.appName ) )
  286.   {
  287.     if ( typeof( eval( "root." + name ) ) == "object" )
  288.       return eval( "root." + name );
  289.   }
  290.   // <CONDITIONAL CODE>
  291.  
  292.   for ( var i = 0; i < root.frames.length; i++ )
  293.   {
  294.     var retFrame = this.getFrameByName( name, root.frames[ i ] );
  295.  
  296.     if ( null != retFrame ) {
  297.       return retFrame;
  298.     }
  299.   }
  300.  
  301.   return null;
  302. }
  303.  
  304.  
  305. /****m* ISJS/getFrameByDocument
  306.  *
  307.  * NAME
  308.  *    getFrameByDocument( document, root )
  309.  *
  310.  * USAGE
  311.  *    document -- document name
  312.  *    root     -- where to start looking for the frame
  313.  *
  314.  * DESCRIPTION
  315.  *    Searches for a frame which holds the 'document' object.
  316.  *
  317.  * RETURN VALUE
  318.  *    [object] -- frame object, if a frame is found
  319.  *    null     -- in any other case
  320.  *
  321.  ****/
  322. function IS_getFrameByDocument( document, root )
  323. {
  324.   if (typeof(IS.Document) != "undefined" && IS.instanceOf(document, IS.Document))
  325.   {
  326.     // 'document' is actually a IS document variable; make the appropriate call
  327.     return ( typeof( root ) != "undefined" )
  328.       ? this.getFrameByDocument( document.getDocument(), root )
  329.       : this.getFrameByDocument( document.getDocument() );
  330.   }
  331.   else
  332.   {
  333.     if ( arguments.length < 2 ) {
  334.         root = top;
  335.     }
  336.  
  337.     if ( document == root.document ) {
  338.         return root;
  339.     }
  340.  
  341.     for ( var i = 0; i < root.frames.length; i++ )
  342.     {
  343.         var retFrame = this.getFrameByDocument( document, root.frames[ i ] );
  344.  
  345.         if ( null != retFrame ) {
  346.             return retFrame;
  347.         }
  348.     }
  349.  
  350.     return null;
  351.   }
  352. }
  353.  
  354.  
  355. /****c* ISJS/ISLib
  356.  *
  357.  * NAME
  358.  *    ISLib()
  359.  *
  360.  * USAGE
  361.  *
  362.  * DESCRIPTION
  363.  *    Space name for all ISJS related functionality.
  364.  *
  365.  * SEE ALSO
  366.  *
  367.  ****/
  368. function ISLib()
  369. {
  370.   // __proto__ initialization
  371.   this.__proto__ = ISLib.prototype;
  372.  
  373.     // type constant(s)
  374.     // ...Innovative Systems JavaScript Library (_IS_)
  375.     this.TYPE_NAMESPACE    = "is_namespace";
  376.  
  377.     // properties
  378.     this.type       = this.TYPE_NAMESPACE;
  379.     this.version    = "1.91";    // library version; DON'T FORGET to update this value every time a change occure to the library
  380.  
  381.     // method(s)
  382.     this.instanceOf            = IS_instanceOf;
  383.     
  384.     this.addVariable        = IS_addVariable;
  385.     this.delVariable        = IS_delVariable;
  386.     
  387.     this.setLibPath         = IS_setLibPath;
  388.     this.getLibPath         = IS_getLibPath;
  389.     this.loadModule         = IS_loadModule;
  390.     
  391.     this.getFrameByName        = IS_getFrameByName;
  392.     this.getFrameByDocument    = IS_getFrameByDocument;
  393.     
  394.     this.isModuleInitialized    = IS_isModuleInitialized;
  395. }
  396.  
  397.  
  398. /****v* ISJS/is_
  399.  *
  400.  * NAME
  401.  *    is
  402.  *
  403.  * DESCRIPTION
  404.  *    Instance of ISLib (one per application).
  405.  *
  406.  * NOTES
  407.  *    If the library is used...
  408.  *        ...with Macromedia Dreamweaver: 'MM._is' object will be instantiated
  409.  *        ...with a Internet browser: 'top._is' object will be instantiated
  410.  *        ...in any other case: '_is' object will be instantiated.
  411.  *
  412.  ****/
  413. if ((typeof(MM) != "undefined") && (typeof(MM._is) == "undefined")) { MM._is = new ISLib(); }
  414. else if ((typeof(top) != "undefined") && (typeof(top.is) == "undefined")) { top._is = new ISLib(); }
  415. else { _is = new ISLib(); }
  416.  
  417. }
  418. var IS = IS_getLibHandle();
  419.  
  420.